/*素材管理*/
import request from '@/utils/request';
import {object2Url} from "@/utils/trans";


/**
 * 获取用户oss配置数据
 */
export async function userOssList(data) {
  const res = await request.post('/business/aliyunoss/userOssList', data);
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}


/**
  * 获取md5加密加盐参数
  */
export async function overallPlatformStatistics(id) {
  const ts = new Date().getTime();
  const ua = navigator.userAgent;
  const us = {
    ts,
    ua,
    merchantId:id  // 商家id
  };
  let url = `/business/MerchantManagement/overallPlatformStatistics${object2Url(us)}`
  const res = await request.get(url, us);
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}


/**
  * 获取md5加密加盐参数
  */
export async function publicFile() {
  const ts = new Date().getTime();
  const ua = navigator.userAgent;
  const us = {
    ts,
    ua,
  };
  let url = `/business/montage/folder/common${object2Url(us)}`
  const res = await request.get(url, us);
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 分页查询剪辑工程列表
 */
export async function projectPage(data) {
  data.max=1  // 筛选最大值>0的“关联活动”
  const res = await request.post('/business/montage/project/page', data);
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}


/**
 分页查询剪辑工程列表_(只查询剩余剪辑数量大于0的数据）
 */
export async function haveProjectPage(data) {
  data.max=1  // 筛选最大值>0的“关联活动”
  const res = await request.post('/business/montage/project/pageId', data);
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}




/**
 非分页查询剪辑工程列表
 */
export async function projectQuery(data) {
  const res = await request.post('/business/montage/project/pageList', data);
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}


// 创建脚本剪辑工程
export async function createScriptProject(data) {
  const res = await request.post('/business/montage/project/createScriptProject', data);
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}


// 获取比例数据
export async function scaleList(data) {
  const res = await request.post('/business/montage/scale/list', data);
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

export async function scriptsDel(data) {
  const res = await request.post('/business/montage/project/delete', data);
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}


// 创建自定义剪辑工程
export async function diyCreate(data) {
  const res = await request.post('/business/montage/diy/create', data);
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 创建图文剪辑工程
export async function imageCreate(data) {
  const res = await request.post('/business/montage/image/create', data);
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}


// 保存及检查脚本剪辑工程
export async function saveAanCheck (data) {
  const res = await request.post('/business/montage/project/saveAanCheck', data)
  if (res.data.code === 2000) {
    return res.data.data
  }
  return Promise.reject(new Error(res.data.msg))
}


// 保存图文剪辑工程
export async function saveImgBuild (data) {
  const res = await request.post('/business/montage/image/saveAndBuild', data)
  if (res.data.code === 2000) {
    return res.data.data
  }
  return Promise.reject(new Error(res.data.msg))
}


// 保存自定义剪辑工程
export async function saveAndBuildDiy (data) {
  const res = await request.post('/business/montage/diy/saveAndBuild', data)
  if (res.data.code === 2000) {
    return res.data.data
  }
  return Promise.reject(new Error(res.data.msg))
}










